using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using XmlObjects;

namespace ProjectConfigurator
{
	public class ObjectReader
	{
		private object theObject;
		private Type theType;
		Dictionary<string, IPropertyItem> properties = new Dictionary<string, IPropertyItem>();


		public Dictionary<string, IPropertyItem> Properties
		{
			get { return properties; }
		}

		public ObjectReader(object theObject)
		{
			this.theObject = theObject;
			theType = theObject.GetType();
			foreach (PropertyInfo propertyInfo in theType.GetProperties())
			{
				properties.Add(propertyInfo.Name, PropertyItem.GetPropertyItem(theObject, propertyInfo));


			}
		}

		public void Save()
		{
			foreach (KeyValuePair<string, IPropertyItem> keyValuePair in properties)
			{
				theType.GetProperty(keyValuePair.Key).SetValue(theObject, keyValuePair.Value.GetValue(), null);
			}
		}
	}
}
